package com.feicheng.controller.main.admin.client;


import com.alibaba.fastjson.JSONObject;
import com.feicheng.common.constant.Constant;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.persistence.entity.VoucherType;
import com.feicheng.persistence.service.IVoucherTypeService;
import com.feicheng.service.IFClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cailongyang
 * @since 2021-12-02
 */
@RestController("/main/admin/client/voucher-type")
@RequestMapping("/main/admin/client/voucher-type")
public class VoucherTypeController {
    @Autowired
    IFClientService fClientService;


    @Autowired
    IVoucherTypeService voucherTypeService;

    // 分页查询
    @GetMapping("/page")
    public ResultInfo voucherTypePage(
            Integer currentPage,
            Integer pageSize,
            String name,
            Boolean statu
    ){
        JSONObject param = new JSONObject();
        param.put(Constant.HTTP.PARAM.CURRENT,currentPage);
        param.put(Constant.HTTP.PARAM.SIZE,pageSize);
        param.put(Constant.ENTITY.VOUCHER_TYPE.NAME,name);
        param.put(Constant.ENTITY.VOUCHER_TYPE.STATU,statu);
        return fClientService.getVoucherTypesByPage(param);
    }


    /**
     * 全查询
     * @return
     */
    @GetMapping("/all")
    public ResultInfo allVouchers(){
        return fClientService.getVouchers(new VoucherType());
    }

    /**
     * 通过id查询
     * @param voucherById
     * @return
     */
    @GetMapping("/info")
    public ResultInfo getVoucherTypeById(Integer voucherTypeById){
        return fClientService.getVoucherTypeById(voucherTypeById);
    }

    // 删除
    @DeleteMapping("/info")
    public ResultInfo deleteVoucherTypeById(Integer voucherTypeId){
        return fClientService.deleteVoucherType(voucherTypeId);
    }

    // 新增
    @PostMapping("/info")
    public ResultInfo newVoucherType(VoucherType voucherType){

        return fClientService.newVoucherType(voucherType);
    }


    // 修改
    @PutMapping("/one")
    public ResultInfo updateVoucherType(VoucherType voucherType){
        return fClientService.updateVoucherType(voucherType);
    }
}
